<template>
  <div style="margin-left: 5rem">
    <el-text>已购机票行程信息:</el-text>
<!--    表格-->
<!--    :data动态绑定数据-->
    <el-table
        :data="tableData"
        style="width: 45rem"
        height="250">
<!--      prop对应tableData具体数据-->
      <el-table-column
          fixed
          prop="flightInform"
          label="航班信息"
          width="150">
      </el-table-column>
      <el-table-column
          prop="notice"
          label="通知"
          width="140">
      </el-table-column>
      <el-table-column prop="operate" label="操作" width="auto">
        <template v-slot="scope">
<!--          点击退票按钮 @click点击事件-->
          <el-button type="danger" size="small" @click="refundTicket(scope.row.flightNo)">退票</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
import request from "@/utils/request.js";

export default {
  name: "Center",
  // 数据
  data() {
    return {
      //表格所有数据
      tableData: [],
      // 登录用户信息
      userInformation: {},
      // 购票数据
      userTicket: {},
    }
  },
  // 初始化加载
  created() {
    // this.getInformation();
    // this.getTableData();
  },
  // 方法
  methods: {
    // 获取订票数据
    getTableData() {
      request.get("/user_ticket/all/?account="+this.userInformation.account).then(res => {
        if (res.data.code === '200') {
          this.tableData = res.data.data;
        }
      })
    },
    // 退票
    refundTicket(flightNo) {
      this.userTicket.flightNo = flightNo
      this.userTicket.account = this.userInformation.account
      request.post("/user_ticket/refundTicket",this.userTicket).then(res=>{
        if (res.data.data===true){
          this.success()
        }
      })
    },
    // 从浏览器sessionStorage中获取用户信息
    getInformation() {
      this.userInformation = JSON.parse(sessionStorage.getItem("user"))
      if (this.userInformation.userRole === '20231111') {
        this.isAdmin = true;
      }
    },
    // 操作成功调用方法
    success(){
      //关闭弹窗
      this.changeEvent = false;
      // 重新获取表格数据
      this.getTableData();
      // 清空提交信息
      this.rowData = {};
      // 显示提交成功
      this.$message.success("操作成功")
    }
  }
}

</script>

<style scoped>

</style>